package operation;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-05-24
 * 22:31
 */
public class deleteoperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("调用删除图书，，，");
        System.out.println("请输入你要删除的图书名：" );
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        boolean b=false;
        for (int i = 0; i < bookList.getSizdUsed(); i++) {
            if (name.equals(bookList.getBooks(i).getName())){
                for (int j = i; j <bookList.getSizdUsed() ; j++) {
                   bookList.setBooks(bookList.getBooks(i+1),i);
                   b=true;
                    System.out.println("删除成功");
                }
                bookList.setSizdUsed(bookList.getSizdUsed()-1);
            }
        }
        if(!b){
            System.out.println("没有要删除的图书");
        }
    }
}
